package com.jingdianjichi.auth.domain.service.impl;

import com.alibaba.fastjson.JSON;
import com.jingdianjichi.auth.domain.convert.AuthRoleBOConverter;
import com.jingdianjichi.auth.domain.entity.AuthRoleBO;
import com.jingdianjichi.auth.domain.service.AuthRoleDomainService;
import com.jingdianjichi.auth.infra.basic.entity.AuthRole;
import com.jingdianjichi.auth.infra.basic.service.AuthRoleService;
import com.jingdianjichi.subject.common.enums.IsDeletedFlagEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 86156
 * @version 1.0
 * @date 2024-10-31 9:55
 */
@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {

    @Resource
    private AuthRoleService authRoleService;

    /**
     * 新增角色
     */
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        if(log.isInfoEnabled()){
            log.info("AuthRoleDomainServiceImpl.add.bo: {}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.instance.authRoleBoToEntity(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        int count = authRoleService.insert(authRole);
        return count>0;
    }

    /**
     * 更新角色信息
     */
    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        if(log.isInfoEnabled()){
            log.info("AuthRoleDomainServiceImpl.update.bo: {}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.instance.authRoleBoToEntity(authRoleBO);
        int count = authRoleService.update(authRole);
        return count>0;
    }

    /**
     * 删除角色信息
     */
    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        if(log.isInfoEnabled()){
            log.info("AuthRoleDomainServiceImpl.delete.authUserBO: {}", JSON.toJSONString(authRoleBO));
        }
        AuthRole authRole = AuthRoleBOConverter.instance.authRoleBoToEntity(authRoleBO);
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        int count = authRoleService.update(authRole);
        return count>0;
    }


}
